import React, {useEffect, useState} from 'react';
import './index.css';
import http from "../../../util/http";
import yd from "./image/yd.svg";

function Academic(props) {
    const [data, setData] = useState({
        xhData: [],
        dfData: []
    });
    useEffect(() => {
        http.doGet('/model/data/get', {type: "org"}).then(res => {
            if (res.status === 200) {
                setData({
                    xhData: res.xhData,
                    dfData: res.dfData
                })
            }
        });
    }, []);

    function openUrl(zzlj) {
        if (zzlj && zzlj !== "") {
            zzlj.startsWith("http") ? window.open(zzlj) : window.open("https://" + zzlj);
        }
    }

    return (
        <div className="portal-academic-main">
            <div className="portal-academic-item portal-academic-xh">
                {/*<div className="portal-academic-item-title">协会会员</div>*/}
                <div className="portal-academic-item-content">
                    {
                        data.xhData && data.xhData.map((item, index) => {
                            return (
                                <div className="portal-academic-item-content-one" onClick={() => openUrl(item.zzlj)} key={index}>
                                    <div className="portal-academic-item-content-one-img">
                                        <img src={yd} alt="圆点"/>
                                    </div>
                                    <div className="portal-academic-item-content-one-text">
                                        {item.zzmc}
                                    </div>
                                </div>
                            )
                        })
                    }
                </div>
            </div>
            <div className="portal-academic-item portal-academic-df">
                {/*<div className="portal-academic-item-title">地方会员</div>*/}
                <div className="portal-academic-item-content">
                    {
                        data.dfData && data.dfData.map((item, index) => {
                            return (
                                <div className="portal-academic-item-content-one" onClick={() => openUrl(item.zzlj)} key={index}>
                                    <div className="portal-academic-item-content-one-img">
                                        <img src={yd} alt="圆点"/>
                                    </div>
                                    <div className="portal-academic-item-content-one-text">
                                        {item.zzmc}
                                    </div>
                                </div>
                            )
                        })
                    }
                </div>
            </div>
        </div>
    );
}

export default Academic;